package com.core.website.service.impl;

import com.core.website.entity.Column;
import com.core.website.entity.OrgAuth;
import com.core.website.mapper.AuthMapper;
import com.core.website.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class AuthServiceImpl implements AuthService {
    @Autowired
    private AuthMapper authMapper;
    @Override
    public List<Column> queryByOrgId(String orgId) {
        return authMapper.queryByOrgId(orgId);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveOrgAuth(OrgAuth orgAuth) {
        authMapper.deleteByOrgId(orgAuth.getOrgId());
        if(null!=orgAuth.getColumnList()&&orgAuth.getColumnList().size()>0){
            for(String columnId:orgAuth.getColumnList()){
                authMapper.saveOrgAuth(orgAuth.getOrgId(),columnId);
            }
        }

    }
}
